package com.shiguiwu.springmybatis.spring.transaction;

import cn.hutool.db.ds.simple.SimpleDataSource;
import org.springframework.boot.jdbc.DataSourceBuilder;

import javax.sql.DataSource;
import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;

/**
 * @description:
 * @author: stone
 * @date: Created by 2021/6/14 15:57
 * @version: 1.0.0
 * @pakeage: com.shiguiwu.springmybatis.spring.transaction
 */
public class DataSourceUtils {
    private static Properties properties = null;
    private static InputStream in = null;


    static {
        try {
            properties = new Properties();
            in = DataSourceUtils.class.getClassLoader().getResourceAsStream("application.yml");
            properties.load(in);
        } catch (IOException e) {
            e.printStackTrace();
        } finally {
            try {
                assert in != null;
                in.close();
            } catch (IOException e) {
                e.printStackTrace();
            }

        }
    }


    public static DataSource getDataSource() {
        DataSourceBuilder dataSourceBuilder = DataSourceBuilder.create();
        dataSourceBuilder.driverClassName("org.h2.Driver");
        dataSourceBuilder.url("jdbc:h2:mem:test");
        dataSourceBuilder.username("SA");
        dataSourceBuilder.password("");

        return dataSourceBuilder.build();
    }

}
